public static void mergeSort(int[] arr, int low, int high) {
    if (low < high) {
        // 计算分割点
        int mid = (low + high) / 2;

        // 递归地对左半部分进行排序
        mergeSort(arr, low, mid);
        // 递归地对右半部分进行排序
        mergeSort(arr, mid + 1, high);

        // 合并排序结果
        merge(arr, low, mid, high);
    }
}

private static void merge(int[] arr, int low, int mid, int high){
    int[] temp = new int[high - low + 1];
    int i = low;
    int j = mid + 1;
    int k = 0;

    while (i <= mid && j <= high) {
        if (arr[i] <= arr[j]) {
            temp[k++] = arr[i++];
        } else {
            temp[k++] = arr[j++];
        }
    }

    while (i <= mid) {
        temp[k++] = arr[i++];
    }

    while (j <= high) {
        temp[k++] = arr[j++];
    }

    for (i = 0; i < temp.length; i++) {
        arr[low + i] = temp[i];
    }
}

public void main(){//add by xjp
    int[] arr = {1, 3, 5, 7, 9, 2, 4, 6, 8, 0};
    mergeSort(arr, 0, arr.length - 1);
    for (int i = 0; i < arr.length; i++) {
        System.out.print(arr[i] + " ");
    }
}